function setReleaseAddress(){
	$.ajax({
		url :interfaceMobileUrl+"/getAddress.json?userid="+userid+"&key="+userkey,
		jsonp: "callback",
	    dataType: "jsonp",
	    success:function(data){
	    	var addresses = eval('(' + data + ')');
			addresses = addresses.list[0]["com.opac.readerHome.domain.Address"];
			$("ul.xuanzedizhi").html("");
			if(addresses.length==undefined){
				addresses = [addresses];
			}
			for(var i=0;i<addresses.length;i++){
				var address = addresses[i].province+addresses[i].city+addresses[i].district+addresses[i].detail;
				var li="<li addressId='"+addresses[i].id+"'><a href='#'><p>"+address+"</p></a></li>";
				if(addresses[i].defaultAddress){
					$("#defaultAddress").html(address);
					li = "<li addressId='"+addresses[i].id+"' class='cur'><a href='#'><p>"+address+"</p></a></li>";
				}
				$("ul.xuanzedizhi").append(li);
			}
			$("#fb_xzdz .xuanzedizhi li").unbind("click");
			$("#fb_xzdz .xuanzedizhi li").click(function(){
				$(this).addClass("cur").siblings().removeClass("cur");
				$("#defaultAddress").html($(this).find("p").html());
			});
		}
	});
}
$(function(){
	$("#releaseToggle").click(function(){
		release();
	});
	$("#toReleaseStep2").click(function(){
		currentBarcodes = "";
		$("#batchReleaseLoanUl li.cur").each(function(){
			var barcode = $(this).attr("barcode");
			currentBarcodes = currentBarcodes+barcode+",";
			currentGlibcode = $(this).attr("gLibcode");
		});
		if(currentBarcodes == ""){
			$("#toReleaseStep2").attr("href","#");
			xfAlert("请选择您要发布的书籍");
		}else{
			if(mobile!=""){
				$("#releasePhone").val(mobile);
			}
			setReleaseAddress();
			currentBarcodes = currentBarcodes.substring(0,currentBarcodes.length-1);
			$("#toReleaseStep2").attr("href","#fabzj_2");
		}
	});
	$("#releaseResultUl li").click(function(){
		$.ui.loadContent("#index",false,false,"up");
	});
});
function fabzj_2_load(){
	if(defaultAddress == undefined){
		getAddressMap();
		$.ui.loadContent("#huoyuedzStep1",false,false,"up");
		xfAlert("请先设置您的活跃地址");
	}
}
function cancleRelease(gLibcode,barcode){
	$.ajax({
		url :interfaceMobileUrl+"/release/cancle.json?userid="+userid+"&key="+userkey,
		data : {
			barcode : barcode,
			gLibcode :gLibcode
		},
		jsonp: "callback",
	    dataType: "jsonp",
	    success:function(data){
	    	if(data=="1"){
	    		xfAlert("取消转借成功");
	    		toMyLoan(userid);
	    	}
		}
	});
}
function release(){
	var phone = $("#releasePhone").val();
	var qq = $("#releaseQQ").val();
	var message = $("#wenbenk").val();
	var addressId = $("li[addressId].cur").attr("addressId");
	$.ajax({
		url :interfaceMobileUrl+"/release/excute.json?userid="+userid+"&key="+userkey,
		data : {
			phone : phone,
			qq : qq,
			message : message,
			addressId : addressId,
			barcodes : currentBarcodes,
			gLibcode :currentGlibcode
		},
		beforeSend:function(){
	    	 $.ui.showMask("发布中...");
	    },
	    complete:function(){
	    },
	    error:function(){
	    	$.ui.hideMask(); 
	    	xfAlert("网络异常");
	    },
		jsonp: "callback",
	    dataType: "jsonp",
	    success:function(data){
	    	$.ui.hideMask(); 
	    	if(data == "1"){
	    		xfAlert("发布成功");
	    		toMyLoan(userid);
	    		indexPage=1;
	    		loadReleaseByCondition(indexPage);
	    		$.ui.loadContent("#releaseResult",false,false,"up");
//	    		$("#releaseToggle").attr("#index");
//	    		var href = location.href;
//				location.href=href.slice(0,href.indexOf('#'));
	    	}else{
	    		xfAlert(data);
	    	}
		}
	});
}